package com.zxx.pattern.statePattern.state;

/**
 * 获得两颗糖果的状态（这个可以不要）
 *
 * @author zxx on 2021/1/14
 */
public class StateWinner implements State {

    private CandyMachine candyMachine;

    public StateWinner(CandyMachine candyMachine) {
        this.candyMachine = candyMachine;
    }

    @Override
    public void onMoneyInserted() {
        System.out.println("正在处理，请勿操作！");
    }

    @Override
    public void onMoneyReturned() {
        System.out.println("正在处理，请勿操作！");
    }

    @Override
    public void onCrankTurned() {
        System.out.println("正在处理，请勿操作！");
    }

    @Override
    public void onCandyPoped() {
        candyMachine.setCandyCount(candyMachine.getCandyCount() - 2);//5-2=3
        System.out.println("正在发放第一颗糖果......");
        System.out.println("正在发放第二颗糖果......");
        System.out.println("糖果发放成功！");

        //设置状态为StateNoMoney（没有投币的状态）
        candyMachine.setState(candyMachine.getNoMoneyState());
    }
}
